import { _decorator, animation, Component, Event, Input, Node, Script, tween, v2, v3, Vec2 } from 'cc';
const { ccclass, property } = _decorator;


@ccclass('BulletTrackingPanel')
export class BulletTrackingPanel extends Component {
    @property(Node)
    monster: Node;

    private monsterX: number
    private monsterY: number = 1280
    private isBullet: boolean = false
    private speed: number = 0
    protected onLoad(): void {
        //初始位置
        this.monsterX = Math.floor(Math.random() * 700) + 10;  //出怪的范围  10 - 710
        this.monster.setPosition(this.monsterX, this.monsterY)
        this.speed = Math.floor(Math.random() * 5) + 5; // 使用Math.floor()函数将小数向下取整
    }

    update(dt) {
        //到底了
        if (this.monsterY < 100) return

        //更新怪物的位置
        this.monsterY = this.monster.position.y - this.speed
        this.monster.setPosition(this.monsterX, this.monsterY)
        //判断位置，通知panel
        if (this.monsterY < 1100 && !this.isBullet) {
            game.EventMgr.emit("monster.enter", this.monster)
            this.isBullet = true
        }

    }
}



